package entities;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.GenericGenerator;

import entities.vo.HogarVO;
import entities.vo.ItemFacturaVO;
import entities.vo.RopaVO;

@Entity
public class ItemFactura implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private long id;
//	@ManyToOne
	private Factura factura;
	private int cant;
	private float precioCobrado;
	
	private Articulo articulo;
	
	
	public ItemFactura() {
		// TODO Auto-generated constructor stub
	}
	
	public ItemFactura(Factura factura) {
		this.factura = factura;
	}
	
	
	public int getCant() {
		return cant;
	}
	public void setCant(int cant) {
		this.cant = cant;
	}
	public float getPrecioCobrado() {
		return precioCobrado;
	}
	public void setPrecioCobrado(float precioCobrado) {
		this.precioCobrado = precioCobrado;
	}
	
	@OneToOne(targetEntity=entities.Articulo.class)
	public Articulo getArticulo() {
		return articulo;
	}
	public void setArticulo(Articulo articulo) {
		this.articulo = articulo;
	}

	@Id
	@GenericGenerator(name = "generator", strategy = "increment")
	@GeneratedValue(generator = "generator")
	//@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public void setItemFacturaVO(ItemFacturaVO itemVO) {
		Articulo articulo =null;
		if(itemVO.getArticulo()!=null){
			if(itemVO.getArticulo() instanceof RopaVO){
				articulo  = new ArticuloRopa();
			}else if(itemVO.getArticulo() instanceof HogarVO){
				articulo = new ArticuloHogar();
			}
		}
		articulo.setArticuloVO(itemVO.getArticulo());
		setCant(itemVO.getCant());
		setId(itemVO.getId());
//		factura = new Factura();
//		factura.setFacturaVO(itemVO.getFactura());
		setPrecioCobrado(itemVO.getPrecioCobrado());
		setArticulo(articulo);
		
	}

	@ManyToOne(targetEntity=entities.Factura.class)	
	//@JoinTable(name="nroFactura")
	public Factura getFactura() {
		return factura;
	}
	public void setFactura(Factura factura) {
		this.factura = factura;
	}
		
}
